/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "StdAfx.h"
#include ".\functionProcessor.h"
#include "PhantomWindow.h"
#include "WindowFactory.h"

#include "PhantomTabCtrlWindow.h"
#include "PhantomButtonWindow.h"
#include "PhantomScrollBar.h"
#include "PhantomStatic.h"
#include "PhantomTreeView.h"
#include "PhantomListView.h"
#include "PhantomComboBox.h"
#include "PhantomListBox.h"
#include "PhantomToolBar.h"
#include "PhantomExplorerWindow.h"

CFunctionProcessor::CFunctionProcessor(void)
{
}

CFunctionProcessor::~CFunctionProcessor(void)
{
}

void CFunctionProcessor::FunctionProcessor(SSI_FunctionAPI& theAPI, HWND theWin, String& Class, String& ExtraData)
{
	// GetClassName
	//  Based on ClassName, get window class
	//  window class is derived from a base window class
	// Pass the API to the window class, which will run the function

	InitWindows();

	myWin = theWin;
//	if(GetClassName(myWin, ClassStr, MINION_MAX_TEXT)){
//		ClassName = ClassStr;
	CPhantomWindow* aWin = Phantom_WindowFromClass(Class);
	if(!aWin){
		theAPI.m_ReturnStatus = STAT_ERR;  // Internal Error
		return;
	}
	if(!aWin->Attach(myWin)){
		theAPI.m_ReturnStatus = STAT_ERR;  // Internal Error
		delete aWin;
		return;
	}
	aWin->SetExtraData(ExtraData);
	aWin->FunctionProcessor(theAPI);
	aWin->Detach();
	delete aWin;
	//}else{
	//	theAPI.m_ReturnStatus = STAT_ERR;
	//}
	Phantom_ClearWindows();
}

int CFunctionProcessor::InitWindows(void)
{
	// This will register all the windows
	// All of these should be deleted by the factory
	
	CPhantomTabCtrlWindow* aTabCtrl = new CPhantomTabCtrlWindow;
	CPhantomButtonWindow* aButton = new CPhantomButtonWindow;
	CPhantomScrollBar* aScroll = new CPhantomScrollBar;
	CPhantomStatic* aStatic = new CPhantomStatic;
	CPhantomTreeView* aTreeView = new CPhantomTreeView;
	CPhantomListView* aListView = new CPhantomListView;
	CPhantomComboBox* aComboBox = new CPhantomComboBox;
	CPhantomListBox* aListBox = new CPhantomListBox;
	CPhantomToolBar* aToolBar = new CPhantomToolBar;
	CPhantomExplorerWindow* aExplorer = new CPhantomExplorerWindow;	
	return 1;
}
